package buaa.leetcode.Bit;

public class DivideTwoNumber {
	public static int divide(int dividend, int divisor) {
        if(divisor==0)
        return Integer.MAX_VALUE;
    
        int res = 0;
        if(dividend==Integer.MIN_VALUE)
        {
            res = 1;
            dividend += Math.abs(divisor);
        }
        if(divisor==Integer.MIN_VALUE)
            return res;
        boolean isNeg = ((dividend^divisor)>>>31==1)?true:false;
        dividend = Math.abs(dividend);
        divisor = Math.abs(divisor);
        int digital = 0;
        while((dividend >> 1) >= divisor){
            divisor = divisor << 1;
            digital++;
        }
        while(digital > 0){
            if(dividend > divisor){
                dividend = dividend - divisor;
                res += 1 << digital; 
            }
            divisor = divisor >> 1;
            digital--;
        }
        return isNeg? -res : res;
    }
	public static void main(String[] args) {
		System.out.println(divide(1, 1));

	}

}
